package written.test;

import java.util.Scanner;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/26 20:02
 * @Description:  https://blog.csdn.net/weixin_30516243/article/details/95162684?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-10.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-10.control
 */
public class Main10 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int x = sc.nextInt();
            if(x==-1) break;
            int y = sc.nextInt();
            if(y==-1) break;
            System.out.println(solve(x, y));
        }
    }
    public static int solve(int firstValue, int secondValue){
        int shortestPathLength;
        int n_fir = (int)Math.ceil((1+Math.sqrt(1 + 4*(firstValue-1)/3))/2);
        int n_sec = (int)Math.ceil((1+Math.sqrt(1 + 4*(secondValue-1)/3))/2);
        if(firstValue == 1){
            shortestPathLength = n_sec - 1;
        }else if(secondValue == 1){
            shortestPathLength = n_fir - 1;
        }else{
            double angle_fir = (n_fir*(n_fir-1)*3+1-firstValue)*2*Math.PI/(6*(n_fir-1));
            double angle_sec = (n_sec*(n_sec-1)*3+1-secondValue)*2*Math.PI/(6*(n_sec-1));
            shortestPathLength = (int)Math.round(Math.sqrt(Math.pow((n_fir-1),2)+Math.pow((n_sec-1), 2)-2*(n_fir-1)*(n_sec-1)*Math.cos(angle_fir-angle_sec)));

        }
        return shortestPathLength;
    }
}
